[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

Simple assignments with =

In general, the types of the left and right operands must be the same; this type must be a data type. In the ordinary assignment with =, the value of the right side is assigned to the object on the left. For simple assignment only, the left operand can be a parenthesized list of lvalues, optionally labelled by an adt name of compatible type, and the right operand either a tuple or an adt whose data members correspond in number and type to the lvalues in the list. The members of the tuple, or the data members of the adt, are assigned in sequence to lvalues in the list. For example,

p	: Point;
x, y	: int;
(x, y) = p;

splits out the coordinates of the Point into x and y. If the left operand of a simple assignment is an adt and the right side is a tuple, then the assignment assigns the members of the tuple to the adt data members; these must correspond in number and type with the members of the tuple.

The constant nil can be assigned to an lvalue of any reference type. This lvalue will compare equal to nil until it is subsequently reassigned. In the Inferno system implementation of Limbo, such an assignment also triggers the abolishment of the object referred to unless other references to it remain.

The left operand of an assignment can be the constant nil to indicate that a value is discarded. This applies in particular to any of the lvalues in a tuple appearing on the left; to extend the example above,

(x, nil) = p;

assigns the x member of the Point p to the variable x.

A special consideration applies to strings. If an int containing a Unicode character is assigned to a subscripted string, the subscript is normally required to lie within the string. As a special case, the subscript's value can be equal to the length of the string (that is, just beyond its end); in this case, the character is appended to the string, and the string's length increases by 1.

A final special case applies to array slices in the form e1[e2:]. Such expressions can lie on the left of =. The right side must be an array of the same type as e1, and its length must be less than or equal to (len e1) - e2. In this case, the elements in the array on the right replace the elements of e1 starting at position e2. The length of the array is unchanged.

The value of an assignment is its new left operand. All the assignment operators associate right-to-left.



[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

Copyright © 1998, Lucent Technologies, Inc. All rights reserved.